<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Welcome extends CI_Controller {
	public function getCate()
	{
		$this->load->library('TaoApi');
		$this->load->model('cate');
		$ary = array(50010788,1801,50023282);
		foreach($ary as $cid)
		{
			$this->readCate($cid);
		}
		//var_dump($c);
	}
	protected function readCate($cid)
	{
		$i=1;
		$c = $this->taoapi->getItemCate($cid);
		foreach($c->item_cats as $k => $v)
		{
			foreach($v as $kk => $vv)
			{
				$vv->order_index = $i++;
				echo '>>'.$vv->cid;
				$this->cate->Insert($vv);
				if($vv->is_parent == 1)
				{
					$this->readCate($vv->cid);
				}
			}
		}
	}
	public function getProperties()
	{
		$params['pagesize'] = 50;
		$params['page'] = 1;
		$this->load->library('TaoApi');
		$this->load->model('cate');
		$this->load->model('prop');
		$cates = $this->cate->GetList($params);
		while (count($cates) > 0)
		{
			foreach($cates as $c)
			{
				$this->writeProp($c['cid']);
			}	
			$params['page']++;
			$cates = $this->cate->GetList($params);
		}
	}
	protected function writeProp($cid)
	{
		$i=1;
		$c = $this->taoapi->getProp($cid);
		foreach($c->itemprops_get_response->item_props as $p)
		{
			$sql = "";
			foreach($p->prop_values as $v)
			{
				$vv->order_index = $i++;
				echo '>>'.$vv->cid;
				$this->cate->Insert($vv);
				if($vv->is_parent == 1)
				{
					$this->readCate($vv->cid);
				}
			}
		}
	}
}